<?php defined('InShopNC') or exit('Access Invalid!');?>

<div class="page">
  <div class="fixed-bar">
    <div class="item-title">
      <h3><?php echo $lang['nc_member_level_manage']?></h3>
      <ul class="tab-base">
        <li><a href="index.php?act=member_level&op=index" ><span><?php echo $lang['nc_manage']?></span></a></li>
        <li><a href="JavaScript:void(0);" class="current"><span><?php echo $output['level']?'编辑':$lang['nc_new']?></span></a></li>
      </ul>
    </div>
  </div>
  <div class="fixed-empty"></div>

  <table class="table tb-type2" id="prompt">
    <tbody>
      <tr class="space odd">
        <th colspan="12"><div class="title">
            <h5><?php echo $lang['nc_prompts'];?></h5>
            <span class="arrow"></span></div></th>
      </tr>
      <tr>
        <td><ul>
            <li>会员消费积分比列请在&nbsp;<a href="index.php?act=operation&op=setting">运营&gt;基本设置</a>&nbsp;中处理</li>
            <li>当前消费与积分兑换比列为：<span style="color: red">1/<?php echo C('points_orderrate')?>=<?php echo intval(1/C('points_orderrate'))?></span></li>
          </ul></td>
      </tr>
    </tbody>
  </table>
  <form id="member_level" action="index.php?act=member_level&op=<?php echo $output['level']?'level_edit':'level_add';?>" enctype="multipart/form-data" method="post">
    <input type="hidden" name="form_submit" value="ok" />
    <?php if($output['level']){?>
      <input type="hidden" name="member_level_id" value="<?php echo $output['level']['member_level_id'];?>" />
    <?php } ?>
    <table class="table tb-type2">
      <tbody>
      <tr class="noborder">
        <td colspan="2" class="required"><label class="validation" for="level_name">渠道名称:</label></td>
      </tr>
      <tr class="noborder">
        <td class="vatop rowform"><input type="text" value="<?php echo $output['level']?$output['level']['level_name']:'';?>" name="level_name" id="level_name" class="txt"></td>
        <td class="vatop tips"></td>
      </tr>
      <tr class="noborder">
        <td colspan="2" class="required"><label class="validation" for="member_name">等级名称:</label></td>
      </tr>
      <tr class="noborder">
        <td class="vatop rowform"><input type="text" value="<?php echo $output['level']?$output['level']['member_name']:'';?>" name="member_name" id="member_name" class="txt"></td>
        <td class="vatop tips"></td>
      </tr>
      <tr class="noborder">
        <td colspan="2" class="required"><label class="validation" for="price_name">渠道价名称:</label></td>
      </tr>
      <tr class="noborder">
        <td class="vatop rowform"><input type="text" value="<?php echo $output['level']?$output['level']['price_name']:'';?>" name="price_name" id="price_name" class="txt"></td>
        <td class="vatop tips"></td>
      </tr>
      <tr>
        <td colspan="2" class="required"><label class="validation" for="min_points">最小积分:</label></td>
      </tr>
      <tr class="noborder">
        <td class="vatop rowform"><input type="number" value="<?php echo $output['level']?$output['level']['min_points']:0;?>" id="min_points" name="min_points" class="txt"></td>
        <td class="vatop tips"></td>
      </tr>
      <tr>
        <td colspan="2" class="required"><label class="validation" for="max_points">最大积分:</label></td>
      </tr>
      <tr class="noborder">
        <td class="vatop rowform"><input type="number" value="<?php echo $output['level']?$output['level']['max_points']:0;?>" id="max_points" name="max_points" class="txt"></td>
        <td class="vatop tips"></td>
      </tr>
      <tr>
        <td colspan="2" class="required"><label class="validation"  for="discount">会员折扣:</label></td>
      </tr>
      <tr class="noborder">
        <td class="vatop rowform"><input type="number" value="<?php echo $output['level']?$output['level']['discount']:100;?>" id="discount" name="discount" class="txt"></td>
        <td class="vatop tips"></td>
      </tr>
<!--      <tr>-->
<!--        <td colspan="2" class="required"><label class="validation"  for="barter_day">无理由退换时间:</label></td>-->
<!--      </tr>-->
<!--      <tr class="noborder">-->
<!--        <td class="vatop rowform"><input type="number"  value="--><?php //echo $output['level']?$output['level']['barter_day']:7;?><!--"  id="barter_day" name="barter_day" class="txt"></td>-->
<!--        <td class="vatop tips"></td>-->
<!--      </tr>-->
      </tbody>
      <tfoot>
      <tr class="tfoot">
        <td colspan="15"><a href="JavaScript:void(0);" class="btn" id="submitBtn"><span><?php echo $lang['nc_submit'];?></span></a></td>
      </tr>
      </tfoot>
    </table>
  </form>
</div>
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/dialog/dialog.js" id="dialog_js" charset="utf-8"></script>
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/jquery-ui/jquery.ui.js"></script>
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/ajaxfileupload/ajaxfileupload.js"></script>
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/jquery.Jcrop/jquery.Jcrop.js"></script>
<link href="<?php echo RESOURCE_SITE_URL;?>/js/jquery.Jcrop/jquery.Jcrop.min.css" rel="stylesheet" type="text/css" id="cssfile2" />
<script type="text/javascript">
  $(function(){
    //按钮先执行验证再提交表单
    var memberLevel=$("#member_level")[0];
    $("#submitBtn").click(function(){
      if($(memberLevel).valid()){
        $(memberLevel).submit();
      }
    });
    $(memberLevel).validate({
      errorPlacement: function(error, element){
        error.appendTo(element.parent().parent().prev().find('td:first'));
      },
      rules : {
        level_name: {
          required : true,
          minlength: 2,
          maxlength: 20,
          remote   : {
            url :'index.php?act=member_level&op=ajax&check=level_name',
            type:'get',
            data:{
              'level_name':memberLevel.level_name.value,
              'min_points':memberLevel.min_points.value,
              'max_points':memberLevel.max_points.value,
              'discount':memberLevel.discount.value,
              'barter_day':memberLevel.barter_day.value
            }
          }
        },
        member_name:{required : true},
        price_name:{required : true},
        min_points : {
          digits: true,
          required : true,
          minlength: 1,
          maxlength: 11
        },
        max_points : {
          digits: true,
          required : true,
          minlength: 1,
          maxlength: 11
        },
        discount : {
          digits: true,
          required : true,
          minlength: 1,
          maxlength: 3
        }
//        ,
//        barter_day : {
//          digits: true,
//          required : true,
//          minlength: 1,
//          maxlength: 3
//        }
      },
      messages : {
        level_name: {
          required : '等级名称不能为空',
          maxlength: '等级名称最短为两个字符',
          minlength: '等级名称最短为20个字符',
          remote   : '等级名称已存在'
        },
        member_name:{required : '等级名称不能为空'},
        price_name:{required : '渠道价名称不能为空'},
        min_points : {
          digits: '积分必须为数字',
          required: '积分不能为空',
          minlength: '积分不能小于1',
          maxlength: '积分不能大于11位'
        },
        max_points  : {
          digits: '积分必须为数字',
          required: '积分不能为空',
          minlength: '积分不能小于1',
          maxlength: '积分不能大于11位'
        },
        discount : {
          digits: '折扣必须为数字',
          required: '折扣不能为空',
          minlength: '折扣只能为1到100间的整数',
          maxlength: '折扣只能为1到100间的整数'
        }
//        ,
//        barter_day : {
//          digits: '无理由退换时间必须为数字',
//          required: '无理由退换时间不能为空',
//          minlength: '无理由退换时间只能为1到999间的整数',
//          maxlength: '无理由退换时间只能为1到999间的整数'
//        }
      }
    });
  });
</script>
